package com.Web.Class;

import com.DAO.Impl.ClassDAOImpl;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 20x
 * @date 2024 - 12 -18
 **/
@WebServlet("/ListClassName")
public class ListClassName extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();

        String classType = req.getParameter("classType")==null ? "篮球" :req.getParameter("classType");
        System.out.println(classType);
        // 创建一个包含所有需要发送的数据的对象
        Map<String, Object> responseData = new HashMap<>();
        responseData.put("ClassAll",new ClassDAOImpl().select(classType, ""));
        // 将对象转换为JSON字符串
        String jsonResponse = gson.toJson(responseData);
        out.write(jsonResponse);
        out.close();
    }
}
